package com.loubobooo.personal.blog.controller.portal;

import com.loubobooo.personal.blog.entity.vo.*;
import com.loubobooo.personal.blog.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller public class TagController {

    @Autowired private TagService tagService;

    //根据标签查询文章
    @RequestMapping("tag/{tagId}")
    public ModelAndView ArticleListByTagView(
            @PathVariable("tagId") Integer tagId) {
        ModelAndView modelAndView = new ModelAndView();
        //设置每页显示条数、
        int pageSize = 10;
        List<ArticleListVo> articleListVoList = tagService.getArticleListByPage(1, null, pageSize, tagId);

        modelAndView.addObject("articleListVoList", articleListVoList);

        //标签信息
        TagVO tagVO = tagService.getTagById(tagId);
        modelAndView.addObject("tagVO", tagVO);

        modelAndView.setViewName("Home/Page/articleListByTag");
        return modelAndView;
    }

    //根据标签查询文章分页
    @RequestMapping("tag/{tagId}/p/{pageNo}")
    public ModelAndView ArticleListByTagAndPageView(
            @PathVariable("pageNo") Integer pageNo, @PathVariable("tagId") Integer tagId) {
        ModelAndView modelAndView = new ModelAndView();

        //设置每页显示条数
        int pageSize = 10;
        List<ArticleListVo> articleListVoList = tagService.getArticleListByPage(1, pageNo, pageSize, tagId);
        modelAndView.addObject("articleListVoList", articleListVoList);
        modelAndView.setViewName("Home/Page/articleListByTag");
        //标签信息
        TagVO tagVO = tagService.getTagById(tagId);
        modelAndView.addObject("tagVO", tagVO);

        return modelAndView;
    }
}
